import 'package:basic_common/common_exports.dart';
import 'package:basic_common/global_getx.dart';
import 'package:basic_profile/model/phrases_data_list.dart';


class CommonPhrasesController extends GetxController {
  TextEditingController contentController = TextEditingController();
  final phrasesList = <PhrasesData>[].obs;
  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    getPhrasesList();
  }


  void addPhrase() async {
    phrasesList.value=[];
    String content = contentController.text;
    if (content.isEmpty) {
      return ToastUtils.toast("内容不能为空，请重新输入");
    }
    HttpData res = await ApiService().addPhrase(data: {
      "creatorNo": globalGetx.doctorInfo!.doctorNo,
      "creatorSource": '2',
      "phrasesContent": content,
      "phrasesType": '2'
    });
    if (res.code == 1) {
      getPhrasesList();
      // update(['phrasesList']);
    }
  }

  /// 获取语句列表
  void getPhrasesList() async {
    HttpData res = await ApiService().getPhraseList(data: {
      "creatorNo": globalGetx.doctorInfo!.doctorNo,
    });
    List dataList = [];
    if (res.code == 1) {
      dataList = res.data;
      if (dataList.length > 0) {
        dataList.forEach((element) {
          PhrasesData phrasesData = PhrasesData.fromJson(element);
          phrasesList.add(phrasesData);
        });
      }
    }
    update(['phrasesList']);
  }
}
